import Vue from 'vue'
import Router from 'vue-router'
import i18n from '@/lang/i18n';
Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/Login'),
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    meta: { title: i18n.t('menu.home'), icon: 'el-icon-s-home' },
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('@/views/home/Home'),
        meta: { title: i18n.t('menu.home'), icon: 'el-icon-s-home'}
      }
    ]
  },
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
